touch命令

touch命令用于修改文件或者目录的时间属性,包括存取时间和更改时间,若文件不存在,系统会建立一个新的文件。

语法

touch [OPTION]... FILE...

参数

示例

创建一个空白文件,如果文件已经存在,它将更改文件的访问时间。

touch /tmp/file.txt

创建多个文件。

touch /tmp/file1.txt /tmp/file2.txt /tmp/file3.txt

模板文件名创建文件。

tmpwatch -am 30 –nodirs /tmp/

修改文件的访问时间并查看文件属性。

touch -a /tmp/file.txt && stat /tmp/file.txt

修改文件的修改时间并查看文件属性。

touch -m /tmp/file.txt && stat /tmp/file.txt

同时修改访问时间和修改时间并设置一个特定的访问与修改时间。

touch -am -t 202007010000.00 /tmp/file.txt && stat /tmp/file.txt

参考

https://linux.die.net/man/1/touch
https://www.runoob.com/linux/linux-comm-touch.html
https://www.interserver.net/tips/kb/touch-command-linux-usage-examples/